home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / mced-1.1.lha / CEDScripts / Outdent.ced < prev    next >
Encoding:
Text File  |  1992-09-02  |  2.6 KB  |  85 lines

  1. /*
  2. **    Outdent.ced
  3. **    
  4. **    $VER: Outdent.ced 1.0 (18.2.95)
  5. **    
  6. **    This script can outdent a line or block. It removes first white char from
  7. **    beginning of current line or each line in block if block is marked.
  8. **    Useful for editing source.
  9. **    
  10. **    This script requires CygnusEd Professional v3.5 (or later) to run.
  11. **    
  12. **    Copyright © 1995 Michael Letowski
  13. */
  14.  
  15. /* Get host */
  16. PARSE SOURCE Com Res Called Resolved Ext Host .
  17. IF Host="REXX" THEN                                                /* From command line */
  18.     ADDRESS "rexx_ced"                                            /* Talk to default CEd */
  19.  
  20. OPTIONS RESULTS                                                        /* Hear it from CEd */
  21.  
  22. GV.TAB="09"X
  23. GV.LF="0A"X
  24. GV.Ops=0                                                                    /* Number of operations for Undo.ced */
  25.  
  26. 'Status CURSORMEMORYX'                                        /* Get position of cursor in line */
  27. Pos=RESULT
  28. 'Status LINEBUFFEROFFSET'                                    /* Get position of line */
  29. Pos=Pos+RESULT
  30.  
  31. 'DM "Outdenting..."'
  32.  
  33. 'Cut block'                                                                /* Cut marked block */
  34. IF RESULT THEN                                                            /* There is a marked block */
  35.     CALL OutdentBlock                                                /* Outdent block */
  36. ELSE                                                                            /* No marked block */
  37.     CALL OutdentLine                                                /* Outdent line */
  38.  
  39. CALL SetClip(UndoClipName(),GV.Ops)                /* Set data for Undo.ced */
  40.     
  41. 'Jump to byte' Pos-GV.Removed                            /* Move cursor to old position */
  42. 'DM'                                                                            /* Restore status line */
  43.  
  44. EXIT                                                                            /* Finished */
  45.  
  46. OutdentBlock:    PROCEDURE EXPOSE GV.
  47.     GV.Removed=0
  48.     'Status BLOCKBUFFER'                                        /* Get buffer */
  49.     ToOutdent=RESULT                                                /* And store it */
  50.     IF Length(ToOutdent)=0 THEN DO                    /* Nothing to outdent */
  51.         'Okay1' "No area marked."
  52.         RETURN
  53.     END
  54.     GV.Ops=GV.Ops+1
  55.     DelPos=1
  56.     DO UNTIL DelPos=1                                                /* For each line... */
  57.         Char=SubStr(ToOutdent,DelPos,1)
  58.         IF Char=GV.TAB | Char=" " THEN
  59.             ToOutdent=DelStr(ToOutdent,DelPos,1)
  60.         DelPos=Pos(GV.LF,ToOutdent,DelPos+1)+1/* Find end of a line */
  61.     END
  62.     'Text' ToOutdent                                                /* Insert back to CED */
  63.     GV.Ops=GV.Ops+RESULT
  64. RETURN
  65.  
  66. OutdentLine:    PROCEDURE EXPOSE GV.
  67.     'Delete line'                                                        /* Delete current line */
  68.     GV.Ops=GV.Ops+RESULT                                        /* Increase number of ops */
  69.     'Status DELETELINEBUFFER'                                /* Get current line */
  70.     PARSE VAR RESULT First 2 Rest                        /* Split it */
  71.     IF First=GV.TAB | First=" " THEN DO            /* Remove first char */
  72.         'Text' Rest                                                        /* Insert rest of line */
  73.         GV.Removed=1
  74.     END
  75.     ELSE DO
  76.         'Text' First||Rest                                        /* Insert whole line */
  77.         GV.Removed=0
  78.     END
  79.     GV.Ops=GV.Ops+RESULT                                        /* Increase number of ops */
  80. RETURN
  81.  
  82. UndoClipName:
  83.     'Status FILEMEM'                                                /* Get address of current file */
  84. RETURN "CEDUndo."Right(D2X(RESULT),8,"0")    /* Prepare unique name */
  85.